home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 280_01 / entab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-11  |  1.8 KB  |  82 lines

  1. /* [ENTAB.c of JUGPDS Vol.46] */
  2. /*
  3. *****************************************************************
  4. *                                *
  5. *    Written by  Hakuo Katayose (JUG-CP/M No.179)        *
  6. *            49-114 Kawauchi-Sanjuunin-machi        *
  7. *            Sendai, Miyagi 980                          *
  8. *            Phone: 0222-61-3219                *
  9. *                                *
  10. *       Modifird by Toshiya Oota   (JUG-CPM No.10)              *
  11. *                   Sakae ko-po 205                 *
  12. *            5-19-6 Hosoda                *
  13. *            Katusikaku Tokyo 124            *
  14. *                                *
  15. *        for MS-DOS Lattice C V3.1J & 80186/V20/V30    *
  16. *                                *
  17. *    Compiler Option: -ccu -k0(1) -ms -n -v -w        *
  18. *                                *
  19. *    Edited & tested by Y. Monma (JUG-CP/M Disk Editor)    *
  20. *            &  T. Ota   (JUG-CP/M Sub Disk Editor)    *
  21. *                                *
  22. *****************************************************************
  23. */
  24.  
  25. /* Library functions for Software Tools */
  26.  
  27. #include "stdio.h"
  28. #include "dos.h"
  29. #include "ctype.h"
  30. #include "tools.h"
  31. #include "toolfunc.h"
  32.  
  33. /* entab - replace blanks by tabs and blanks */
  34.  
  35. void    main(argc, argv)
  36. int    argc;
  37. char    **argv;
  38.  
  39. {
  40. int    c, col, newcol, tabs[MAXLINE];
  41. void    settab();
  42. int    tabpos();
  43.  
  44.     settab(tabs, MAXLINE);
  45.     col = 1;
  46.     do {
  47.         newcol = col;
  48.         while ( ( c = getchar() ) == BLANK ) {
  49.             newcol++;
  50.             if ( tabpos( newcol, tabs ) == YES ) {
  51.                 putchar( TAB );
  52.                 col  = newcol;
  53.                  }
  54.             }
  55.         for ( ; col < newcol; col++ )
  56.             putchar( BLANK );
  57.         if ( c == EOF )
  58.             break;
  59.         putchar( c );
  60.         col = ( c == NEWLINE ) ? 1 : col + 1;
  61.         } while(1);
  62. }
  63.  
  64. int    tabpos( col, tabs )
  65. int    col;
  66. char    tabs[];
  67. {
  68.     return( (col > MAXLINE) ? YES : (int) tabs[col] );
  69. }
  70.  
  71.  
  72. void    settab(tabs, maxlen)
  73. int    maxlen;
  74. char    tabs[];
  75. {
  76.     int    i;
  77.  
  78.     for(i = 0; i <= maxlen; i++)
  79.         tabs[i] = ( ( i % 8 == 1 ) ? YES : NO );
  80.     return;
  81. }
  82.